<?php
/**
 * Created by PhpStorm.
 * User: Qch
 * Date: 2016/9/8
 * Time: 16:49
 */

namespace J\Storage;


use J\Util\File  as FileServer;

/**
 * 文件缓存 [文件名 => 文件内容]
 *    适用于
 */
class FileCache extends Cache
{
    protected $dir;

    public function get($key, $column = null)
    {
        return FileServer::get($key, $column);
    }

    public function set($pairs, $keys=null)
    {
        foreach ($pairs as $file => $value){
            FileServer::add($file, $value);
        }
    }

    public function hasItem($key, $expire = null)
    {
        return is_file($key) and (!$expire or filemtime($key)>$expire);
    }

    function itemDelete($key)
    {
        return FileServer::remove($key);
    }

    /**
     * 清空缓存
     *
     */
    public function clear()
    {
        FileServer::rmdir($this->dir);
    }
}